package
{
	import away3d.cameras.Camera3D;
	import away3d.containers.Scene3D;
	import away3d.containers.View3D;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	public class CustomWorld3D extends Sprite
	{
		
		protected var scene:Scene3D;
		protected var camera:Camera3D;
		protected var view:View3D;
		
		public function CustomWorld3D():void
		{
			_initWold3D();
			initialize()
		}
		
		public function initialize():void
		{
		
		}
		
		private function _initWold3D():void
		{
			view = new View3D();
			scene = view.scene;
			camera = view.camera;
			view.camera.focus = 1;
			view.camera.zoom = 1000;
			addChild(view);
			addEventListener(Event.ENTER_FRAME, updateWorld3D);
		}
		
		protected function center(target:DisplayObject):void
		{
			if (target is Stage)
			{
				view.x = Stage(target).stageWidth / 2
				view.y = Stage(target).stageHeight / 2
			}
			else
			{
				view.x = target.width / 2;
				view.y = target.height / 2;
			}
		}
		
		protected function updateWorld3D(event:Event):void
		{
			view.render();
		}
		
		public function dispose():void
		{
			removeEventListener(Event.ENTER_FRAME, updateWorld3D);
		}
	}

}